/**
 * Created by lx on 2017/9/25.
 */
angular.module('service.tablenum', [
        "ngResource",
    ])
    .service('TableNumService', TableNumService);
TableNumService.$inject = ['$resource'];
function TableNumService($resource) {

    // 通过shopid添加桌台
    this.addTableNum = function (table, sucF, errF) {
        var resource = $resource(merchanturl + "shoptable");
        return resource.save(table, sucF, errF);
    };

    // 通过tableid获取桌台详情
    this.getTableNum = function (tableid, sucF, errF) {
        var resource = $resource(merchanturl + "shoptable/:tableid");
        return resource.get({tableid: tableid}, sucF, errF);
    };

    // 通过shopid获取桌台
    this.getTableNumByShopId = function (shopid, sucF, errF) {
        var resource = $resource(merchanturl + "shoptable/bystidshopid/:shopid");
        return resource.query({shopid: shopid}, sucF, errF);
    };

    // 修改桌台
    this.saveTableDetail = function (shopid, table, sucF, errF) {
        var resource = $resource(merchanturl + "shoptable/:shopid/:tableid");
        return resource.save({shopid: shopid, tableid: table.tableid}, table, sucF, errF);
    };

    // 通过shopid和tableid获取桌台信息
    this.getDetailByTableId = function (shopid, tableid, sucF, errF, cache) {
        if (!cache) {
            cache = false;
        }
        var resource = $resource(merchanturl + "shodev/byshoptable/:shopid/:tableid", {}, {
            query: {cache: cache, method: 'GET', isArray: true}
        });
        return resource.query({shopid: shopid, tableid: tableid}, sucF, errF);
    };

    // 二维码
    this.get_ticket = function (info) {
        var resource = $resource(wx_jssdkurl + "jsapi/jsticket");
        return resource.save({}, info)
    };

    // 通过shopid和groupID获取桌台列表
    this.getTableList = function (shopid, groupid, sucF, errorF) {
        var resource = $resource(merchanturl + "shoptable/bysidgid/:shopid/:groupid");
        return resource.query({shopid: shopid, groupid: groupid}, sucF, errorF)
    };

    // 新增设备表
    this.addEquip = function (body, sucF, errF) {
        var resource = $resource(merchanturl + "shodev");
        return resource.save(body, sucF, errF)
    };

    // 删除设备
    this.deleteEquip = function (devid, sucF, errF) {
        var resource = $resource(merchanturl + "shodev/:devid");
        return resource.remove({devid: devid}, sucF, errF)
    };

    // 绑定、解绑设备
    this.shopDevRelation = function (dev, sucF, errF) {
        var resource = $resource(merchanturl + "shodev/:devid");
        return resource.save({devid: dev.devid}, dev, sucF, errF)
    };

    // 重新绑定设备
    this.modifyDev = function (tableid, devid, body, sucF, errF) {
        var resource = $resource(merchanturl + "shodev/:tableid/devid");
        return resource.save({tableid: tableid, devid: devid}, body, sucF, errF);
    };

    this.getalldetail = function (tablelist, sucF, errF) {
        var resource = $resource(merchanturl + 'shoptablegroup/:shopid', {}, {
            save: {
                method: "POST",
                isArray: true,
            }
        });
        return resource.save({}, tablelist, sucF, errF);
    };

    // 重新绑定设备根据devid
    this.modifyDevByDevId = function (devid, body, sucF, errF) {
        var resource = $resource(merchanturl + "shodev/:devid");
        return resource.save({devid: devid}, body, sucF, errF);
    };

    // 获取桌台信息
    this.getShopTable = function (tableid, sucF, errF) {
        var resource = $resource(merchanturl + "shoptable/:shopid/:tableid");
        return resource.get({tableid: tableid}, sucF, errF);
    };
    // 修改桌台信息
    this.updateShopTable = function (shopTable, sucF, errF) {
        var resource = $resource(merchanturl + "shoptable/:shopid/:tableid");
        return resource.save({shopid: shopTable.shopid, tableid: shopTable.tableid}, shopTable, sucF, errF);
    };

    // 删除table
    this.deleteTable = function (shopid, tableid, sucF, errF) {
        var resource = $resource(merchanturl + "shoptable/byids/:tableid");
        return resource.remove({shopid: shopid, tableid: tableid}, sucF, errF);
    };

    // 获取桌台电量
    this.getShopTableByEle = function (devid, sucF, errF) {
        var resource = $resource(deviceurl + "devele/devid/:devid");
        return resource.get({devid: devid}, sucF, errF);
    };

}
